package com.yuyou.activity.util.util;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.yuyou.activity.util.bean.MessageResult;

public class MessageUtil {
    private static  final Logger logger = LoggerFactory.getLogger(MessageUtil.class);

    public static MessageResult sendCode(String messageUrl,String messageKey,String phoneNo, String type, String content) {

        MessageResult sendResult =null  ;
        try {
            Map<String, String> params= new HashMap<>();
            params.put("content", content);
            params.put("token", MD5Util.md5Hex(phoneNo+messageKey));
            params.put("phoneNo", phoneNo);
            String result = HttpClientUtil.client(messageUrl,params);
            if(result != null){
                MessageResult mr = JSON.parseObject(result,new TypeReference<MessageResult>() {});
                if(mr != null){
                    sendResult = mr;
                }
            }
            logger.info(String.format("开启短信接口,手机号码是%s,短信内容是%s,接口返回结果是%s", phoneNo,content,result));
        } catch (Exception e) {
            logger.error("sms not available", e);
        }


        return sendResult;
    }
}
